package com.talent.jiwen.ui.widgets;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.talent.jiwen.R;
import com.talent.jiwen.util.Validators;

public class TagView extends LinearLayout {
    private TextView oneTag;
    private TextView twoTag;
    private TextView threeTag;

    public TagView(Context context) {
        super(context);
        init();
    }

    public TagView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TagView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        inflate(getContext() , R.layout.view_tag , this);

        oneTag = (TextView)findViewById(R.id.oneTag);
        twoTag = (TextView)findViewById(R.id.twoTag);
        threeTag = (TextView)findViewById(R.id.threeTag);
    }

    public void bindData(String tagInfo){
        if (!Validators.isEmpty(tagInfo)){
            String[] tags = tagInfo.split(",");
            if (tags.length == 1){
                oneTag.setVisibility(VISIBLE);
                oneTag.setText(tags[0]);
                twoTag.setVisibility(GONE);
                threeTag.setVisibility(GONE);
            }else if (tags.length == 2){
                oneTag.setVisibility(VISIBLE);
                oneTag.setText(tags[0]);
                twoTag.setVisibility(VISIBLE);
                twoTag.setText(tags[1]);
                threeTag.setVisibility(GONE);
            }else {
                oneTag.setVisibility(VISIBLE);
                oneTag.setText(tags[0]);
                twoTag.setVisibility(VISIBLE);
                twoTag.setText(tags[1]);
                threeTag.setVisibility(VISIBLE);
                threeTag.setText(tags[2]);
            }
        }else{
            oneTag.setVisibility(GONE);
            twoTag.setVisibility(GONE);
            threeTag.setVisibility(GONE);
        }
    }
}
